package src.Packets;

import src.Main;
import src.Players.Player;
import src.NPCs.NPC;
import src.Skills.Thieving;

public class NPCOption2
{
    public NPCOption2(Player p)
    {
        if(p == null || p.inStream == null)
        {
            return;
        }
        if(!p.npcOption2)
        {
            p.clickId = p.inStream.readUnsignedWordBigEndianA();
            if (p.clickId < 1 || p.clickId > Main.m.ge.maxNPCs || Main.m.ge.npcs[p.clickId] == null)
            {
                return;
            }
            p.clickX = Main.m.ge.npcs[p.clickId].absX;
            p.clickY = Main.m.ge.npcs[p.clickId].absY;
            p.npcOption2 = true;
        }
        if(Main.m.ge.npcs[p.clickId] == null || Main.m.ge.npcs[p.clickId].isDead)
        {
            p.npcOption2 = false;
            return;
        }
        p.requestFaceTo(p.clickId);
        if(Main.m.ge.getDistance(p.clickX, p.clickY, p.absX, p.absY) == 1)
        {
            p.npcOption2 = false;
            NPC n = Main.m.ge.npcs[p.clickId];
            switch(n.npcType)
            {
                case 520: //Shop Keeper
                    p.viewShop(1);
                break;
                case 521: //Shop Assistant
                    p.viewShop(2);
                break;
                case 1: //Man.
                case 2: //Man.
                case 3: //Man.
                case 4: //Woman.
                case 5: //Woman.
                case 6: //Woman.
                case 7: //Farmer.
                case 1714: //Male H.A.M. member.
                case 1715: //female H.A.M. member.
                case 15: //Warrior.
                case 187: //Rogue.
                case 2234: //Master farmer.
                case 2235: //Master farmer.
                case 9: //Guard.
                case 10: //Guard.
                case 32: //Guard.
                case 1305: //Fremennik.
                case 23: //Knight.
                case 26: //Knight.
                case 34: //Watchman.
                case 1904: //Menaphite Thug.
                case 1905: //Menaphite Thug.
                case 20: //Paladin.
                case 67: //Gnome.
                case 68: //Gnome.
                case 69: //Gnome.
                case 21: //Hero.
                    Thieving t = new Thieving(p);
                    t.thieveNPC(p.clickId);
                    t = null;
                break;
                default:
                    Main.m.log("[" + p.playerIndex + "-" + p.username + "] NPC option 2 " + n.npcType);
                break;
            }
        }
    }
}